<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="刘清政">
  <meta name="keyword" content="hexo-theme">
  
    <link rel="shortcut icon" href="/css/images/logo.png">
  
  <title>
    
      python/MySQL入门/3-Windows安装MySQL | Justin-刘清政的博客
    
  </title>
  <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/tomorrow.min.css" rel="stylesheet">
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/css/plugins/gitment.css">

  
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>
  
    
<script src="/js/qrious.js"></script>

  
  
    
<script src="/js/gitment.js"></script>

  
  

  
<meta name="generator" content="Hexo 4.2.0"></head>
<div class="wechat-share">
  <img src="/css/images/logo.png" />
</div>

  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>Justin-刘清政的博客</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">主页</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">标签</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">归档</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">关于我</a>
          
        </li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">主页</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">标签</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">归档</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">关于我</a>
            
          </li>
        
      </ul>
    </div>
  </div>
</header>

    <div id="article-banner">
  <h2>python/MySQL入门/3-Windows安装MySQL</h2>



  <p class="post-date">2020-10-22</p>
    <!-- 不蒜子统计 -->
    <span id="busuanzi_container_page_pv" style='display:none' class="">
        <i class="icon-smile icon"></i> 阅读数：<span id="busuanzi_value_page_pv"></span>次
    </span>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h1 id="一、下载"><a href="#一、下载" class="headerlink" title="一、下载"></a>一、下载</h1><p>第一步：打开网址，<a href="https://www.mysql.com/" target="_blank" rel="noopener">https://www.mysql.com</a> ，点击downloads之后跳转到<a href="https://www.mysql.com/downloads" target="_blank" rel="noopener">https://www.mysql.com/downloads</a></p>
<p><img src="https://tva1.sinaimg.cn/large/0081Kckwgy1gjzav1seg4j326t0u04qp.jpg" alt="image-20201023152925899"></p>
<p>第二步 ：跳转至网址<a href="https://dev.mysql.com/downloads/" target="_blank" rel="noopener">https://dev.mysql.com/downloads/</a> ，拉到最下方，下载社区版</p>
<p><img src="https://tva1.sinaimg.cn/large/0081Kckwgy1gjzaw2i3cjj31qu0u0gtg.jpg" alt="image-20201023153029480"></p>
<p>第三步 ：进入地址：<a href="https://dev.mysql.com/downloads/" target="_blank" rel="noopener">https://dev.mysql.com/downloads/</a></p>
<p><img src="https://tva1.sinaimg.cn/large/0081Kckwgy1gjzaxluqn1j31hj0u044s.jpg" alt="image-20201023153158033"></p>
<p>第四步：<a href="https://dev.mysql.com/downloads/mysql/，这里我们看到的是最新版本，点击Archives，选择windows版，5.7版本" target="_blank" rel="noopener">https://dev.mysql.com/downloads/mysql/，这里我们看到的是最新版本，点击Archives，选择windows版，5.7版本</a></p>
<p><img src="https://tva1.sinaimg.cn/large/0081Kckwgy1gjzaz756kmj310v0u013m.jpg" alt="image-20201023153330255"></p>
<p>第五步：<a href="https://downloads.mysql.com/archives/community/，选择平台版本下载" target="_blank" rel="noopener">https://downloads.mysql.com/archives/community/，选择平台版本下载</a></p>
<p><img src="https://tva1.sinaimg.cn/large/0081Kckwgy1gjzcfyngpoj320a0u0gux.jpg" alt="image-20201023153649516"></p>
<h1 id="二、解压"><a href="#二、解压" class="headerlink" title="二、解压"></a>二、解压</h1><p>下载的zip文件解压，将解压之后的文件夹放到任意目录下，这个目录就是mysql的安装目录。</p>
<h1 id="三、配置"><a href="#三、配置" class="headerlink" title="三、配置"></a>三、配置</h1><p>打开mysql目录，新建文件为my.ini或者my.cnf</p>
<h2 id="3-1-my-ini参考配置"><a href="#3-1-my-ini参考配置" class="headerlink" title="3.1 my.ini参考配置"></a>3.1 my.ini参考配置</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">[mysql]</span><br><span class="line"><span class="comment"># 设置mysql客户端默认字符集</span></span><br><span class="line">default-character-set=utf8 </span><br><span class="line">[mysqld]</span><br><span class="line"><span class="comment">#设置3306端口</span></span><br><span class="line">port = <span class="number">3306</span> </span><br><span class="line"><span class="comment"># 设置mysql的安装目录</span></span><br><span class="line">basedir=C:\Program Files\mysql<span class="number">-5.7</span><span class="number">.30</span>-winx64 </span><br><span class="line"><span class="comment"># 设置mysql数据库的数据的存放目录</span></span><br><span class="line">datadir=C:\Program Files\mysql<span class="number">-5.7</span><span class="number">.30</span>-winx64\data </span><br><span class="line"><span class="comment"># 允许最大连接数</span></span><br><span class="line">max_connections=<span class="number">200</span></span><br><span class="line"><span class="comment"># 服务端使用的字符集默认为8比特编码的latin1字符集</span></span><br><span class="line">character-set-server=utf8</span><br><span class="line"><span class="comment"># 创建新表时将使用的默认存储引擎</span></span><br><span class="line">default-storage-engine=INNODB</span><br></pre></td></tr></table></figure>

<h2 id="3-2-安装并初始化mysql"><a href="#3-2-安装并初始化mysql" class="headerlink" title="3.2 安装并初始化mysql"></a>3.2 安装并初始化mysql</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1  在C:\Program Files\mysql-5.7.30-winx64\bin路径下执行</span></span><br><span class="line">mysqld --initialize-insecure <span class="comment"># 初始化</span></span><br><span class="line"><span class="comment"># 2 执行完后，打开data目录，会看到 xx.err,初始密码就在这个文件中</span></span><br></pre></td></tr></table></figure>

<h2 id="3-3-安装MySQL服务"><a href="#3-3-安装MySQL服务" class="headerlink" title="3.3 安装MySQL服务"></a>3.3 安装MySQL服务</h2><p>以管理员身份打开cmd窗口后，将目录切换到你解压文件的bin目录，输入mysqld install回车运行</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mysqld –install  </span><br><span class="line">mysqld –install MySQL57  <span class="comment"># 指定服务名</span></span><br></pre></td></tr></table></figure>

<h1 id="四、环境变量"><a href="#四、环境变量" class="headerlink" title="四、环境变量"></a>四、环境变量</h1><p>在系统变量PATH后面添加: 你的mysql bin文件夹的路径（如C:\Program Files\mysql-5.7.30-winx64\bin）</p>
<p>这样在任意位置敲击 mysql，都能找到该命令</p>
<h1 id="六、启动mysql服务"><a href="#六、启动mysql服务" class="headerlink" title="六、启动mysql服务"></a>六、启动mysql服务</h1><p>以管理员身份在cmd中输入：<code>net start mysql</code></p>
<p>服务启动成功之后，就可以登录了，输入<code>mysql -u root -p</code>（密码在data目录下xx.err文件中）</p>
<h2 id="6-1-停止mysql"><a href="#6-1-停止mysql" class="headerlink" title="6.1 停止mysql"></a>6.1 停止mysql</h2><p><code>net stop mysql</code>：停止mysql</p>
<p>注意：<strong>在windows操作系统上没有重启mysql服务的命令，如果要重启服务，只能先stop再start。</strong></p>
<h1 id="七-、修改密码"><a href="#七-、修改密码" class="headerlink" title="七 、修改密码"></a>七 、修改密码</h1><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 登陆</span></span><br><span class="line">mysql -uroot </span><br><span class="line"><span class="comment"># 修改密码</span></span><br><span class="line">alter user <span class="string">'root'</span>@<span class="string">'localhost'</span> identified by <span class="string">'lqz123'</span>;</span><br><span class="line"><span class="comment"># 退出</span></span><br><span class="line">exit</span><br></pre></td></tr></table></figure>

<h1 id="八-、忘记root密码"><a href="#八-、忘记root密码" class="headerlink" title="八 、忘记root密码"></a>八 、忘记root密码</h1><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># mysqld启动时，跳过授权表，跳过tcp/ip连接</span></span><br><span class="line">--skip-grant-tables  跳过授权表</span><br><span class="line">--skip-networking   跳过tcp/ip连接，不让远程用户登录，否则远程用户不用密码可以直接登录</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#1  来到bin路径下执行（跳过授权表启动）</span></span><br><span class="line">mysqld --skip-grant-tables</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2 再打开一个cmd窗口,今日mysql</span></span><br><span class="line">mysql </span><br><span class="line"><span class="comment"># 3 手工把授权表加载到内存</span></span><br><span class="line">mysql&gt; flush privileges;</span><br><span class="line">mysql&gt;  alter user root@<span class="string">'localhost'</span> identified by <span class="string">'123456'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4 关闭刚刚启动的mysqld，重新正常启动就可以了</span></span><br></pre></td></tr></table></figure>



</section>
    <!-- Tags START -->
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/python/MySQL%E5%85%A5%E9%97%A8/16-MySQL%E6%80%A7%E8%83%BD%E5%88%86%E6%9E%90%E4%B9%8BExplain/">
        <span class="nav-arrow">← </span>
        
          python/MySQL入门/16-MySQL性能分析之Explain
        
      </a>
    
    
      <a class="nav-right" href="/python/MySQL%E5%85%A5%E9%97%A8/2-%E5%88%9D%E8%AF%86MySQL/">
        
          python/MySQL入门/2-初识MySQL
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
      <div class="money-like">
        <div class="reward-btn">
          赏
          <span class="money-code">
            <span class="alipay-code">
              <div class="code-image"></div>
              <b>使用支付宝打赏</b>
            </span>
            <span class="wechat-code">
              <div class="code-image"></div>
              <b>使用微信打赏</b>
            </span>
          </span>
        </div>
        <p class="notice">点击上方按钮,请我喝杯咖啡！</p>
      </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
      <div class="qrcode">
        <canvas id="share-qrcode"></canvas>
        <p class="notice">扫描二维码，分享此文章</p>
      </div>
    
    <!-- 二维码 END -->
    
      <!-- Gitment START -->
      <div id="comments"></div>
      <!-- Gitment END -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
  <!-- 不蒜子统计 -->
    <strong class="toc-title">目录</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#一、下载"><span class="toc-nav-text">一、下载</span></a></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#二、解压"><span class="toc-nav-text">二、解压</span></a></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#三、配置"><span class="toc-nav-text">三、配置</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#3-1-my-ini参考配置"><span class="toc-nav-text">3.1 my.ini参考配置</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#3-2-安装并初始化mysql"><span class="toc-nav-text">3.2 安装并初始化mysql</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#3-3-安装MySQL服务"><span class="toc-nav-text">3.3 安装MySQL服务</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#四、环境变量"><span class="toc-nav-text">四、环境变量</span></a></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#六、启动mysql服务"><span class="toc-nav-text">六、启动mysql服务</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#6-1-停止mysql"><span class="toc-nav-text">6.1 停止mysql</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#七-、修改密码"><span class="toc-nav-text">七 、修改密码</span></a></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#八-、忘记root密码"><span class="toc-nav-text">八 、忘记root密码</span></a></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'http://www.liuqingzheng.top/python/MySQL入门/3-Windows安装MySQL/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', 'http://file.muyutech.com/error-img.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== 'http://file.muyutech.com/error-img.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


  <script>
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });
  </script>



  <script>
    var gitmentConfig = "liuqingzheng";
    if (gitmentConfig !== 'undefined') {
      var gitment = new Gitment({
        id: "python/MySQL入门/3-Windows安装MySQL",
        owner: "liuqingzheng",
        repo: "FuckBlog",
        oauth: {
          client_id: "32a4076431cf39d0ecea",
          client_secret: "94484bd79b3346a949acb2fda3c8a76ce16990c6"
        },
        theme: {
          render(state, instance) {
            const container = document.createElement('div')
            container.lang = "en-US"
            container.className = 'gitment-container gitment-root-container'
            container.appendChild(instance.renderHeader(state, instance))
            container.appendChild(instance.renderEditor(state, instance))
            container.appendChild(instance.renderComments(state, instance))
            container.appendChild(instance.renderFooter(state, instance))
            return container;
          }
        }
      })
      gitment.render(document.getElementById('comments'))
    }
  </script>




    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
<!-- 不蒜子统计 -->
<span id="busuanzi_container_site_pv">
     本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
<span class="post-meta-divider">|</span>
<span id="busuanzi_container_site_uv" style='display:none'>
     本站访客数<span id="busuanzi_value_site_uv"></span>人
</span>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



  <p class="copyright">
    &copy; 2021 | Proudly powered by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank">小猿取经</a>
    <br>
    Theme by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank" rel="noopener">小猿取经</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("//cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>





<!-- Baidu Tongji -->

<script>
    var _baId = 'c5fd96eee1193585be191f318c3fa725';
    // Originial
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?" + _baId;
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
</script>


<script src="/js/script.js"></script>


<script src="/js/search.js"></script>


<script src="/js/load.js"></script>



  <span class="local-search local-search-google local-search-plugin" style="right: 50px;top: 70px;;position:absolute;z-index:2;">
      <input type="search" placeholder="站内搜索" id="local-search-input" class="local-search-input-cls" style="">
      <div id="local-search-result" class="local-search-result-cls"></div>
  </span>


  </body>
</html>